package com.susu.mybatis.conteroller;

import com.github.pagehelper.PageInfo;
import com.susu.mybatis.entity.Book;
import com.susu.mybatis.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class BookController {


    @Autowired
    private BookService bookService;

    //分页查询
    @GetMapping("/bookList")
    public String getList(@RequestParam(defaultValue = "1") Integer pageNum, Model model){
        PageInfo<Book> pageInfo = bookService.getList(pageNum);
        model.addAttribute("list",pageInfo);
        return "/bookList";
    }

    //批量删除
    @PostMapping("/del")
    public String delBooks(Integer[] ids){
        bookService.delBooks(ids);
        return "redirect:/bookList";
    }
}
